#pragma once
// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: Transform3DDisplayItem.h
// Description: Transform3DDisplayItem Classes
//      Author: Ziming Li
//     Created: 2022-01-24
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef Transform3DDisplayItem_h
#define Transform3DDisplayItem_h

#include "blinkit/blink/renderer/platform/graphics/paint/DisplayItem.h"
#include "blinkit/blink/renderer/platform/transforms/TransformationMatrix.h"
#include "blinkit/blink/renderer/wtf/Assertions.h"
#include "blinkit/blink/renderer/wtf/PassOwnPtr.h"

namespace blink {

class BeginTransform3DDisplayItem final : public PairedBeginDisplayItem {
public:
    BeginTransform3DDisplayItem(
        const DisplayItemClient& client,
        Type type,
        const TransformationMatrix& transform,
        const FloatPoint3D& transformOrigin)
        : PairedBeginDisplayItem(client, type, sizeof(*this))
        , m_transform(transform)
        , m_transformOrigin(transformOrigin)
    {
        ASSERT(DisplayItem::isTransform3DType(type));
    }

    void replay(GraphicsContext&) const override;
    void appendToWebDisplayItemList(const IntRect&, WebDisplayItemList*) const override;

    const TransformationMatrix& transform() const { return m_transform; }
    const FloatPoint3D& transformOrigin() const { return m_transformOrigin; }

private:
#ifndef NDEBUG
    void dumpPropertiesAsDebugString(WTF::StringBuilder&) const final;
#endif
#if ENABLE(ASSERT)
    bool equals(const DisplayItem& other) const final
    {
        return DisplayItem::equals(other)
            && m_transform == static_cast<const BeginTransform3DDisplayItem&>(other).m_transform
            && m_transformOrigin == static_cast<const BeginTransform3DDisplayItem&>(other).m_transformOrigin;
    }
#endif

    const TransformationMatrix m_transform;
    const FloatPoint3D m_transformOrigin;
};

class EndTransform3DDisplayItem final : public PairedEndDisplayItem {
public:
    EndTransform3DDisplayItem(const DisplayItemClient& client, Type type)
        : PairedEndDisplayItem(client, type, sizeof(*this))
    {
        ASSERT(DisplayItem::isEndTransform3DType(type));
    }

    void replay(GraphicsContext&) const override;
    void appendToWebDisplayItemList(const IntRect&, WebDisplayItemList*) const override;

private:
#if ENABLE(ASSERT)
    bool isEndAndPairedWith(DisplayItem::Type otherType) const final
    {
        return DisplayItem::transform3DTypeToEndTransform3DType(otherType) == type();
    }
#endif
};

} // namespace blink

#endif // Transform3DDisplayItem_h
